package com.leoman.plz_p.views.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.leoman.plz_p.R;
import com.leoman.plz_p.interfaces.ChangePasswordView;
import com.leoman.plz_p.presenter.ChangePasswordPresenter;
import com.leoman.plz_p.weidget.NavBar;

import butterknife.Bind;
import butterknife.OnClick;
import cn.com.corelib.base.BaseActivity;
import cn.com.corelib.utils.ToastMgr;

/**
 * Created by guoh on 2018/9/2.
 */
public class ChangePasswordActivity extends BaseActivity<ChangePasswordView,ChangePasswordPresenter> implements ChangePasswordView{

    @Bind(R.id.nav)
    NavBar nav;
    @Bind(R.id.et_number)
    EditText etNumber;
    @Bind(R.id.et_old_password)
    EditText etOldPassword;
    @Bind(R.id.et_new_password)
    EditText etNewPassword;
    @Bind(R.id.et_re_password)
    EditText etRePassword;
    @Bind(R.id.tv_confirm)
    TextView tvConfirm;


    public static Intent getLaunchIntent(Context context) {
        Intent intent = new Intent(context, ChangePasswordActivity.class);
        return intent;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.ac_change_password;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        nav.setTitle("修改密码");
    }

    @Override
    protected ChangePasswordPresenter createPresenter() {
        return new ChangePasswordPresenter();
    }

    @OnClick(R.id.tv_confirm)
    public void onViewClicked() {
        if (isEmpty(etNumber)) {
            ToastMgr.show("请输入学籍号");
            return;
        }
        if (isEmpty(etOldPassword)) {
            ToastMgr.show("请输入旧密码");
            return;
        }
        if (isEmpty(etNewPassword)) {
            ToastMgr.show("请输入新密码");
            return;
        }
        if (isEmpty(etRePassword)) {
            ToastMgr.show("请再次输入新密码");
            return;
        }
        if (!TextUtils.equals(getText(etNewPassword), getText(etRePassword))) {
            ToastMgr.show("两次新密码输入不一致");
            return;
        }
        getPresenter().resetPassword(getText(etNumber), getText(etOldPassword), getText(etRePassword));
    }

    @Override
    public void obtainResetSuccess() {
        ToastMgr.show("修改密码成功");
    }
}
